<template>
	<!--历史调研页  -->
	<view class="u-demo back" style="padding-top: 20rpx;height: 100%;">
		 <view class="item " v-for="(item,index) in wenjuan_listData" :key="index" style="margin-bottom: 20rpx;">
			<text class="f30 title" >调研标题： {{item.name}}</text>
			<view class="flex flex-pack-justify Jbetween fontWeight">
				<view class="flex" >
					<text style="" type="text" class="f26 c999"  />填写人:</text>
					<text class="f26 c999" style="margin-left:20rpx;">{{item.user_name}}</text>
				</view>
				<text class="f26 c999">{{item.createtime}}</text>
			</view>
			<uni-transition :duration="1000" :mode-class="'slide-bottom'"  :show="true" >
				<view class="warp-status" style="display: flex;justify-content: space-between;margin-top: 30rpx;">
					<text v-if="item.exam_id==1"  class="warning" style="font-weight: bold;font-size: 25rpx;">当前状态：待审批</text>
					<text  v-if="item.exam_id==3" class="success" style="font-weight: bold;font-size: 25rpx;">当前状态：已通过</text>
               <text  v-if="item.exam_id==4" class="success" style="font-weight: bold;font-size: 25rpx;">当前状态：初审通过</text>
					<text  v-if="item.exam_id==2" class="error" style="font-weight: bold;font-size: 25rpx;">当前状态：未通过</text>
					<u-button v-if="item.exam_id==2" type="error" size="mini"  @click="resetSubmit(item)">重新提交</u-button>
				</view>
			</uni-transition>
		</view>
		<view style="margin-top: 50rpx;">
			<u-loadmore
			  :status="status" 
			  :loading-text="loadingText" 
			  :loadmore-text="loadmoreText" 
			  :nomore-text="nomoreText" 
				 />
		</view>

		
	</view>
</template>

<script>
	import util from '@/utils/util.js'
	export default {
		data() {
			return {
				isStatus:3,
				status: 'nomore',
				loadingText: '努力加载中',
				loadmoreText: '轻轻上拉',
				nomoreText: '实在没有了',
				wenjuan_listData:[],
				business_specific_type:"",
				user_type:"",
				openid:''//用户授权位移标识openid
			}
		},
		/*下拉刷新*/
		onPullDownRefresh: function() {
			this.status='loading'
			let openID=uni.getStorageSync('openid')
			// 如果存在手机  直接登录
			let userInfo = uni.getStorageSync('userInfo');
			if (userInfo) {
				this.user_type = userInfo.user_type   //暂时不要删除
				this.business_specific_type=userInfo[0].business_specific_type
			}
			console.log('user',this.user_type)
			console.log('缓存获取的optnid',openID)
			this.openid=openID
			// 获取历史调研列表数据
			this.getWenjuan_listData()
			setTimeout(() => {
				//关闭下拉刷新
				uni.stopPullDownRefresh()
			}, 1000)
		},
      onShow() {
         // 获取历史调研列表数据
         this.getWenjuan_listData()
      },
		onLoad() {
			this.status='loading'
			let openID=uni.getStorageSync('openid')
			// 如果存在手机  直接登录
			let userInfo = uni.getStorageSync('userInfo');
			if (userInfo) {
				this.user_type = userInfo.user_type   //暂时不要删除
				this.business_specific_type=userInfo[0].business_specific_type
			}
			console.log('user',this.user_type)
			console.log('缓存获取的optnid',openID)
			this.openid=openID
			
		},
		methods: {
			// 审核状态未通过重新提交
			// 重新提交
			resetSubmit:function(item){
				// 此处需要后台返回描述字段
				uni.navigateTo({
					url: "../../template/keyboardPay/index?id="+item.survey_id+'&name='+item.name+'&description='+item.description+'&status='+item.exam_id+'&fail='+item.fail+'&submitType=update&isInOutStatus=2'
				})//酒店记账跳转
			},
			getWenjuan_listData:function(){
				this.wenjuan_listData=[]
				var API=this.$store.state.vue_XAPI
				console.log('获取api',API)
				var that=this
				this.$.tipLoading('加载中...')
				// uni.showToast({
				// 	title: '加载中...',
				// 	icon: 'loading',
				// 	duration: 1000
				// });
				this.status='loading'
				uni.request({
					method: 'POST',
					url: API+'/index.php/api/index/wenjuan_list',
					dataType: 'json',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
					   openid:that.openid
					},
					success: function (res) {
						// 数据加载完成，隐藏弹窗
						uni.hideLoading();
						if(res.data.code==1){
							that.status='nomore'
							res.data.data.forEach(item=>{
								item.createtime=util.getYMDHMS(item.createtime*1000)
							})
							that.wenjuan_listData=res.data.data
						}else{
							that.status='nomore'
							that.wenjuan_listData=[]
						}
						console.log('获取历史调研结果获取历史调研结果获取历史调研结果获取历史调研结果',that.wenjuan_listData)
					}
				});
				
			},
			offsetTopChange(index) {
				this.offsetTop = index == 0 ? 0 : index == 1 ? 120 : 200;
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 0
				})
			},
			enableChange(index) {
				this.enable = index == 0 ? true : false;
			},
			fixed() {
				this.$refs.uToast.show({
					type: 'warning',
					title: '触发吸顶'
				})
			},
			unfixed() {
				this.$refs.uToast.show({
					type: 'success',
					title: '取消吸顶'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.item {
	    margin: 20rpx 30rpx;
	    border-bottom: 1px #e5e5e5 solid;
	    padding-bottom: 20rpx;
		.warp-status{
			.success{
				color: #0F9B4D;
			}
			.warning{
				color: #FF8E03;
			}
			.error{
				color:#FC3E2C;
			}
		}
	}
	text {
	    display: block;
	}
	.title {
	    font-weight: bold;
	    margin-bottom: 20rpx;
	}
</style>